package br.ufal.ic.sd.testes;

import org.junit.*;

import br.ufal.ic.sd.loggerApi.ClientSideConection;
import br.ufal.ic.sd.loggerApi.LoggerDistribuidoApi;
import br.ufal.ic.sd.serverSide.serverOptions.CentralServer;
import static org.junit.Assert.*;

/**
 * The class <code>LoggerDistribuidoApiTest</code> contains tests for the class <code>{@link LoggerDistribuidoApi}</code>.
 *
 * @author Thiago Ribeiro
 * @version $Revision: 1.0 $
 */
public class LoggerDistribuidoApiTest {
	
	private LoggerDistribuidoApi result;
	private CentralServer c;

	/**
	 * Teste no construtor;
	 * 
	 * @throws Exception
	 */
	@Test
	public void testLoggerDistribuidoApi() throws Exception {
		result = new LoggerDistribuidoApi();
		assertNotNull(result);
	}

	/**
	 * Run the LoggerDistribuidoApi getInstance() method test.
	 *
	 * @throws Exception
	 *
	 */
	@Test
	public void testGetInstance() throws Exception {

		result = LoggerDistribuidoApi.getInstance();

		assertNotNull(result);
	}

	
	/**
	 * Run the Boolean log(LevelsDeLog,String) method test.
	 *
	 * @throws Exception
	 *
	 */
	@Test
	public void testLog() throws Exception {
		
		LoggerDistribuidoApi.LevelsDeLog level = LoggerDistribuidoApi.LevelsDeLog.ALL;
		String mensagem = "";

		assertEquals("log enviado", result.log(level, mensagem));
	}

	/**
	 * Run the Boolean setConexao(ClientSideConection) method test.
	 *
	 * @throws Exception
	 *
	 */
	@Test
	public void testSetConexao() throws Exception {
		
		ClientSideConection conexao = new ClientSideConection("localhost", 9000);
		assertTrue(result.setConexao(conexao));
	}

	

	/**
	 * Perform pre-test initialization.
	 * @throws Exception
	 */
	@Before
	public void setUp() throws Exception 
	{
		//inicio o servidor numa nova thread
//		c = new CentralServer();
//		Thread t = new Thread(c);
//		t.start();
		
		//inicio a classe a se testar
		result = new LoggerDistribuidoApi();
		result.setConexao(new ClientSideConection("localhost", 9000));
		
	}

	/**
	 * Perform post-test clean-up.
	 * 
	 * @throws Exception
	 */
	@After
	public void tearDown() throws Exception {
		//c.serverMain.finalizarServidor();
	}

	/**
	 * Launch the test.
	 *
	 * @param args the command line arguments
	 *
	 */
	public static void main(String[] args) 
	{
		new org.junit.runner.JUnitCore().run(LoggerDistribuidoApiTest.class);
	}
}